//
//  DYTabBarController.swift
//  IOSweibo09
//
//  Created by mac on 16/3/20.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class DYTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.setValue(DYTabBar(), forKey: "tabBar")
        addChildViewController()
            }
    
    func addChildViewController() {
        let homeVC = DYHomeController()
        addChildViewController(homeVC, title: "首页", imageName: "tabbar_home")
        
        
        let messageVC = DYMessageController()
        addChildViewController(messageVC, title: "消息", imageName: "tabbar_message_center")
        let discoverVC = DYDiscoverController()
        addChildViewController(discoverVC, title: "搜索", imageName: "tabbar_discover")
        
        let profileVC = DYProfileController()
        addChildViewController(profileVC, title: "我", imageName: "tabbar_profile")

    }
    func addChildViewController(controller: UIViewController, title: String, imageName: String) {
        controller.title = title
        controller.tabBarItem.image = UIImage(named: imageName)
        let highedImage = imageName + "_highlighted"
        
        controller.tabBarItem.selectedImage = UIImage(named: highedImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Highlighted)
        
        addChildViewController(UINavigationController(rootViewController: controller))
    }
}
